package servlet;

import dao.Dao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/updateOrderInfoServlet")
public class UpdateOrderInfoServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String address = request.getParameter("address");
        String receivename = request.getParameter("receivename");
        String tele = request.getParameter("tele");
        String orderid = request.getParameter("orderid");
        Dao dao = new Dao();
        int i = dao.updateOrderInfo(address, receivename, tele, orderid);
        if (i > 0) {
            response.sendRedirect(request.getContextPath() + "/findAllOrderServlet");
        } else {
            request.setAttribute("updateInfo", "修改订单失败，请重试");
            request.getRequestDispatcher("/updateOrderInfo.jsp?orderid" + orderid).forward(request, response);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
